﻿using DevExpress.XtraGrid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QuotationSoftware.DialogForm
{
    public partial class CreateRegion : Form
    {
        mForm myMainForm;
        public CreateRegion(mForm _MainForm)
        {
            InitializeComponent();

            myMainForm = _MainForm;
            if (Global.listRegion == null)
            {
                string messageError = "";
                Common.ERROR_CODE.ERROR_CODE_ITEMS_SELECT errCode = Business.Region.getRegionForFrm(ref messageError, ref Global.listRegion);
                if (errCode == Common.ERROR_CODE.ERROR_CODE_ITEMS_SELECT.SYSTEM_ERROR)
                    MessageBox.Show(Common.myString.NETWORK_ERROR);
            }
        }

        private void bt_Region_AddNew_Click(object sender, EventArgs e)
        {
            if (tb_Domain.Text.Trim().Length == 0)
            {
                MessageBox.Show("Không để trống tên miền");
            }
            else
            {
                myMainForm.addCheckedRegions(gridRegionTemp.DataSource as List<Business.Region>, tb_Domain.Text);
            }
        }

        private void gridViewPRTemp_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (gridViewPRTemp.IsNewItemRow(e.FocusedRowHandle))
            {
                gridViewPRTemp.FocusedRowHandle = -1;
                RegionFrm frm = new RegionFrm(Global.listRegion, this);
                frm.ShowDialog();
            }
        }

        internal void ShowCheckedRegions(List<Business.Region> data)
        {
            gridRegionTemp.DataSource = data;
        }

        private void gridViewPRTemp_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
        {

        }
    }
}
